var stoneGame = function (piles) {
  let n = piles.length;
  // dp[i][j] 定义：区间 piles[i..j] 内先手可以获得的相对分数
  const dp = Array.from(new Array(n), () => new Array(n));
  for (let i = 0; i < n; i++) {
    dp[i][i] = piles[i];
  }
  for (let j = 1; j < n; j++) {
    for (let i = j - 1; i >= 0; i--) {
      dp[i][j] = Math.max(piles[i] - dp[i + 1][j], piles[j] - dp[i][j - 1]);
    }
  }
  return dp[0][n - 1] > 0;
};
